import java.util.Scanner;

public class MaxSubArraySum {
    // 方法用于找到数组中子数组的最大和
    public static int maxSubArraySum(int[] nums) {
        int currentMax = nums[0];
        int globalMax = nums[0];

        for (int i = 1; i < nums.length; i++) {
            // 更新当前最大值
            currentMax = Math.max(nums[i], currentMax + nums[i]);
            // 更新全局最大值
            globalMax = Math.max(globalMax, currentMax);
        }

        return globalMax;
    }

    // 测试方法
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        // 创建数组并读取元素
        int[] nums = new int[n];
        System.out.println("请输入数组的元素:");
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        System.out.println(maxSubArraySum(nums));

    }
}
